package com.coding.service.impl;

import com.coding.base.pojo.BaseModel;
import com.coding.base.pojo.PageQueryModel;
import com.coding.dao.MainPlaceDao;
import com.coding.pojo.MainPlace;
import com.coding.service.MainPlaceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @auther wangchenghao
 * @date 2020/7/30
 **/
@Service
public class MainPlaceImpl implements MainPlaceService {
    @Autowired
    MainPlaceDao mainPlaceDao;
    @Override
    public void getwayplace(int way_id, BaseModel baseModel) throws Exception {

        MainPlace mainPlace=new MainPlace();
        mainPlace.setMain_way_id(way_id);
        List<MainPlace> mainPlaces=mainPlaceDao.queryAllWithMain(mainPlace);
        if (mainPlaces.size()>0){
            baseModel.setSucceed("查询该诗路主要景点成功",mainPlaces);
        }else {
            baseModel.setFailure("查询盖诗路主要景点失败");
        }
    }

    @Override
    public void getBannerPlace(BaseModel baseModel) throws Exception {
        MainPlace mainPlace=new MainPlace();
        mainPlace.setMain_tag("banner");
        List<MainPlace> mainPlaces=mainPlaceDao.queryAll(mainPlace);
        if (mainPlaces.size()>0){
            baseModel.setSucceed("获得轮播图成功",mainPlaces);
        }else {
            baseModel.setFailure("获得轮播图失败");
        }
    }

    @Override
    public void getListMainPlace(PageQueryModel pageQueryModel, BaseModel baseModel) throws Exception {
        MainPlace mainPlace=new MainPlace();
        mainPlace.setMain_tag("list");
        PageHelper.startPage(pageQueryModel.getPage(), pageQueryModel.getSize());
        List<MainPlace> mainPlaceList=mainPlaceDao.queryAllWithMain(mainPlace);
        PageInfo pageInfo = new PageInfo(mainPlaceList);
        mainPlaceList = pageInfo.getList();
        if (mainPlaceList.size() == 0) {
            if (pageInfo.getPageNum() > 1) {
                baseModel.setFailure("已经没有下一页了");
            } else {
                baseModel.setOther(2, "没有符合条件的景点");
            }
            return;
        }
        baseModel.setSucceed("查询成功，符合条件的景点共" + mainPlaceList.size() + "条", mainPlaceList);
    }

    @Override
    public void getMainPlace(int mainplace_id, BaseModel baseModel) throws Exception {
        MainPlace mainPlace=mainPlaceDao.selectSingle(mainplace_id);
        if (mainPlace!=null){
            baseModel.setSucceed("成功获得诗景信息",mainPlace);
        }else {
            baseModel.setFailure("获得诗景信息失败");
        }
    }

    @Override
    public void searchMainPlace(String text, BaseModel baseModel) throws Exception {
        List<MainPlace> mainPlaceList=mainPlaceDao.searchMainPlace(text);
        if (mainPlaceList!=null){
            baseModel.setSucceed("成功获得诗景信息",mainPlaceList);
        }else {
            baseModel.setFailure("获得诗景信息失败");
        }
    }
}
